<!--
Copyright (c) 2019-2026, Hossein Moein
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
* Neither the name of Hossein Moein and/or the DataFrame nor the
  names of its contributors may be used to endorse or promote products
  derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html>
<html>

<head>
<style>
body {
  background-image: linear-gradient(Azure, AliceBlue, GhostWhite, WhiteSmoke);
}
</style>
</head>

<body style="font-family: Georgia, serif">

  <font size="+3">&#8592;</font> <a href="https://hosseinmoein.github.io/DataFrame/docs/HTML/DataFrame.html">Back to Documentations</a><BR><BR>
  
  <table border="1">

    <tr bgcolor="lightblue">
      <th>Signature</th> <th>Description</th>
    </tr>
    <tr bgcolor="Azure">
      <td>
<pre class="code_syntax" style="color:#000000;background:#ffffff00;"><span class="line_wrapper">truct  StringStats  <span style="color:#800080; ">{</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_size <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>        <span style="color:#696969; ">// Average of sizes</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  std_size <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>        <span style="color:#696969; ">// Standard deviation of sizes</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_alphabets <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>   <span style="color:#696969; ">// Average number of a - z, A - Z</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_caps <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>        <span style="color:#696969; ">// Average number of A - Z</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_digits <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>      <span style="color:#696969; ">// Average number of 0 - 9</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_spaces <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>      <span style="color:#696969; ">// Average number of ' '</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_arithmetic <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// Average number of + - / *</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_line_feed <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span>   <span style="color:#696969; ">// Average number of \n</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">    <span style="color:#696969; ">// Punctuations. Anything that's not an alphabet, digit, space, line feed,</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">// or arithmetic operators.</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">//</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">double</span>  avg_puncts <span style="color:#800080; ">{</span> <span style="color:#008c00; ">0</span> <span style="color:#800080; ">}</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"><span style="color:#800080; ">}</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span></pre>
      </td>
      <td>
        A set of statistics about a string column
      </td>
    </tr>

  </table>

  <BR>

  <table border="1">

    <tr bgcolor="lightblue">
      <th>Signature</th> <th>Description</th> <th>Parameters</th>
    </tr>
    <tr bgcolor="Azure">
      <td>
<pre class="code_syntax" style="color:#000000;background:#ffffff00;"><span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">template</span><span style="color:#800080; ">&lt;</span><a href="https://github.com/hosseinmoein/DataFrame/blob/master/include/DataFrame/Utils/Concepts.h#L208">StringOnly</a> T<span style="color:#800080; ">&gt;</span></span>
<span class="line_wrapper">StringStats</span>
<span class="line_wrapper">get_str_col_stats<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">const</span> <span style="color:#800000; font-weight:bold; ">char</span> <span style="color:#808030; ">*</span>col_name<span style="color:#808030; ">)</span> <span style="color:#800000; font-weight:bold; ">const</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span></pre>
      </td>
      <td>
        This call takes a string column as input and returns a set of statistics about the strings in that column. You could use these statistics to figure out the characteristics of the strings in the column. Or you could use the statistics to determine if a new string is acceptable for this column, or ...<BR>
      </td>
      <td width="35%">
        <B>T</B>: Type of the input column. Based on the concept, it can only be either of these types: <I>std::string</I>, <I>VirtualString</I>, <I>const char *</I>, or <I>char *</I>.<BR>
        <B>col_name</B>:  Name of the input column.<BR>
      </td>
    </tr>

  </table>

<pre class="code_syntax" style="color:#000000;background:#ffffff00;"><span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">static</span> <span style="color:#800000; font-weight:bold; ">void</span> test_get_str_col_stats<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span>  <span style="color:#800080; ">{</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">    <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">cout</span> <span style="color:#808030; ">&lt;</span><span style="color:#808030; ">&lt;</span> <span style="color:#800000; ">"</span><span style="color:#0f69ff; ">\n</span><span style="color:#0000e6; ">Testing get_str_col_stats(  ) ...</span><span style="color:#800000; ">"</span> <span style="color:#808030; ">&lt;</span><span style="color:#808030; ">&lt;</span> <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">endl</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">typedef</span> StdDataFrame64<span style="color:#800080; ">&lt;</span><span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">string</span><span style="color:#800080; ">&gt;</span> StrDataFrame<span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">    StrDataFrame    df<span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">try</span>  <span style="color:#800080; ">{</span></span>
<span class="line_wrapper">        df<span style="color:#808030; ">.</span>read<span style="color:#808030; ">(</span><span style="color:#800000; ">"</span><span style="color:#0000e6; ">data/SHORT_IBM.csv</span><span style="color:#800000; ">"</span><span style="color:#808030; ">,</span> io_format<span style="color:#800080; ">::</span>csv2<span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">        <span style="color:#800000; font-weight:bold; ">auto</span>    str_col <span style="color:#808030; ">=</span> df<span style="color:#808030; ">.</span>get_index<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">        <span style="color:#696969; ">// IBM data has no string columns except for its index. Load the</span></span>
<span class="line_wrapper">        <span style="color:#696969; ">// index column as a regular column, so we have something to test</span></span>
<span class="line_wrapper">        <span style="color:#696969; ">// A sample string in this column is "2020-10-21"</span></span>
<span class="line_wrapper">        <span style="color:#696969; ">//</span></span>
<span class="line_wrapper">        df<span style="color:#808030; ">.</span>load_column<span style="color:#808030; ">(</span><span style="color:#800000; ">"</span><span style="color:#0000e6; ">ISO Dates</span><span style="color:#800000; ">"</span><span style="color:#808030; ">,</span> <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">move</span><span style="color:#808030; ">(</span>str_col<span style="color:#808030; ">)</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">        <span style="color:#800000; font-weight:bold; ">const</span> StringStats   result <span style="color:#808030; ">=</span> df<span style="color:#808030; ">.</span>get_str_col_stats<span style="color:#800080; ">&lt;</span><span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">string</span><span style="color:#800080; ">&gt;</span><span style="color:#808030; ">(</span><span style="color:#800000; ">"</span><span style="color:#0000e6; ">ISO Dates</span><span style="color:#800000; ">"</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_size <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008000; ">10.0</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// Average size of each string is 10 chars</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>std_size <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// Every string is the same size</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_alphabets <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// No alphabets</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_caps <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// No Capital alphabets</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">        <span style="color:#696969; ">// 80% of all chars in the entire column are digits</span></span>
<span class="line_wrapper">        <span style="color:#696969; ">//</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_digits <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008000; ">0.8</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_spaces <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// No spaces</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">        <span style="color:#696969; ">// 20% of all chars in the entire column are arithmetic operators</span></span>
<span class="line_wrapper">        <span style="color:#696969; ">//</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_arithmetic <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008000; ">0.2</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_line_feed <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// No new lines</span></span>
<span class="line_wrapper">        assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>avg_puncts <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>  <span style="color:#696969; ">// No punctuations</span></span>
<span class="line_wrapper">    <span style="color:#800080; ">}</span></span>
<span class="line_wrapper">    <span style="color:#800000; font-weight:bold; ">catch</span> <span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">const</span> DataFrameError <span style="color:#808030; ">&amp;</span>ex<span style="color:#808030; ">)</span>  <span style="color:#800080; ">{</span></span>
<span class="line_wrapper">        <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">cout</span> <span style="color:#808030; ">&lt;</span><span style="color:#808030; ">&lt;</span> ex<span style="color:#808030; ">.</span>what<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span> <span style="color:#808030; ">&lt;</span><span style="color:#808030; ">&lt;</span> <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">endl</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper">    <span style="color:#800080; ">}</span></span>
<span class="line_wrapper"><span style="color:#800080; ">}</span></span>
<span class="line_wrapper"></span></pre>

  <BR><img src="https://github.com/hosseinmoein/DataFrame/blob/master/docs/LionLookingUp.jpg?raw=true" alt="C++ DataFrame"
       width="200" height="200" style="float:right"/>

</body>
</html>

<!--
Local Variables:
mode:HTML
tab-width:4
c-basic-offset:4
End:
-->
